<?php

namespace App\Listeners\OpenShop;

use App\Events\OpenShop\AutoRefundDecorationDepositEvent;
use App\Listeners\BaseListener;
use App\Service\OpenShop\OrderService;
use Exception;

class AutoRefundDecorationDepositListener extends BaseListener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Handle the event.
     *
     * @param AutoRefundDecorationDepositEvent $autoRefundDecorationDepositEvent
     * @return void
     * @throws Exception
     */
    public function handle(AutoRefundDecorationDepositEvent $autoRefundDecorationDepositEvent)
    {
        $orderNo = $autoRefundDecorationDepositEvent->orderNo;
        try{
            ini_set('memory_limit', '500M');
            OrderService::refundDecorationDeposit($orderNo);
        }catch (Exception $exception){
            logException("装修保证金发起退款失败", $exception, ["orderNo" => $orderNo], true, true);
        }
    }
}
